package com.spzx.product.api.factory;

import com.spzx.common.core.constant.ServiceNameConstants;
import com.spzx.common.core.domain.R;
import com.spzx.product.api.RemoteCategoryService;
import com.spzx.product.api.domain.vo.CategoryVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.util.List;

/**
 * projectName: spzx-parent
 *
 * @author: 王宝贵
 * time: 2024/10/8 16:30 周二
 * description: 商品服务降级处理 需要继承FallbackFactory 重写方法  做兜底处理
 */
@Slf4j
public class RemoteCategoryFallbackFactory implements FallbackFactory<RemoteCategoryService> {

    @Override
    public RemoteCategoryService create(Throwable throwable) {

        log.error("远程调用:{}调用出现了问题", ServiceNameConstants.PRODUCT_SERVICE);

        return new RemoteCategoryService() {
            @Override
            public R<List<CategoryVo>> getOneCategory(String resource) {
                return R.fail("获取一级分类失败,异常是：" +throwable.getMessage());
            }

            @Override
            public R<List<CategoryVo>> tree(String resource) {
                return R.fail("获取分类标签失败,异常是：" +throwable.getMessage());
            }
        };
    }
}